package com.opencloud.iot.provider.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.opencloud.common.model.PageParams;
import com.opencloud.iot.client.model.entity.IotStreng;
import com.opencloud.iot.provider.mapper.IotStrengMapper;
import com.opencloud.iot.provider.service.IotStrengService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 动量服务
 * @author yeyong
 */

@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class IotStrengServiceImpl implements IotStrengService {
    @Autowired
    private IotStrengMapper iotStrengMapper;

    @Override
    public IPage<IotStreng> findListPage(PageParams pageParams) {
        IotStreng query = pageParams.mapToObject(IotStreng.class);
        QueryWrapper<IotStreng> queryWrapper = new QueryWrapper();
        queryWrapper.lambda()
                .eq(ObjectUtils.isNotEmpty(query.getWatchmac()),IotStreng::getWatchmac,query.getWatchmac())
                .orderByDesc(IotStreng::getTimestamp);
        return iotStrengMapper.selectPage(new Page(pageParams.getPage(),pageParams.getLimit()),queryWrapper);
    }
}
